package com.yjhb.android.sbz.v2.adapter

import android.app.Activity
import android.content.Context
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.yjhb.android.sbz.R
import com.yjhb.android.sbz.v2.entity.ReportStep
import com.jojo.android.zxlib.base.BaseRecyclerAdapterV2
import com.jojo.android.zxlib.tool.ZxTimeTool
import com.jojo.android.zxlib.view.nine.NineGridImageView
import com.jojo.android.zxlib.view.nine.NineGridImageViewAdapter
import com.jojo.android.zxlib.view.preview.PreviewBuilder
import com.jojo.android.zxlib.view.preview.util.PreviewUtil


/**
 *  创建者 zx
 *  创建时间 2021/4/7 11:05
 */
class V2ReportContentAdapter(con: Context) : BaseRecyclerAdapterV2<BaseRecyclerAdapterV2.BaseHolder, ReportStep>(con) {


    override fun getLayoutId(): Int {
        return R.layout.item_report_content_step_v2
    }

    override fun onBindViewHolder(holder: BaseHolder, position: Int) {

        val nineGridImageView = holder.findViewById<NineGridImageView<String>>(R.id.nineGridImageView)
        val adapter = object : NineGridImageViewAdapter<String>() {
            override fun onDisplayImage(context: Context, imageView: ImageView, t: String) {
                Glide.with(context).load(t)
                        .apply(RequestOptions().placeholder(com.jojo.android.zxlib.R.drawable.xui_ic_default_img))
                        .into(imageView)
            }
        }
        holder.findViewById<TextView>(R.id.content_tv).text = if (entity.state == 0) {
            "举报理由：" + entity.content?.content
        } else {
            "辩诉陈词：" + entity.content?.content
        }
        holder.findViewById<TextView>(R.id.nickname_tv).text = entity.nickname
        holder.findViewById<TextView>(R.id.time_tv).text = ZxTimeTool.date2String(entity.time)
        holder.findViewById<TextView>(R.id.content_title).text = if (entity.state == 0) "举报内容" else "辩诉内容"
        Glide.with(context).load(entity.avatar)
                .error(R.mipmap.test_head)
                .into(holder.findViewById(R.id.head_iv))
        nineGridImageView.setAdapter(adapter)
        nineGridImageView.setShowStyle(0)
        nineGridImageView.setMaxSize(9)
        nineGridImageView.setImagesData(entity.content?.urls)
        nineGridImageView.setItemImageClickListener { imageView, index, list ->
            val infos = PreviewUtil.ImagesToPreviewInfo(list, imageView)
            PreviewBuilder.from(context as Activity)
                    .setCurrentIndex(index)
                    .setImgs(infos)
                    .setDrag(false)
                    .start()
        }

    }

    override fun getHolder(v: View): BaseHolder {
        return BaseHolder(v)
    }

}